<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>欢迎使用房屋租赁系统</title>

    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <!-- Custom fonts for this template-->
    <link href="vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
    <link
            href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i"
            rel="stylesheet">

    <!-- Custom styles for this template-->
    <link href="css/sb-admin-2.min.css" rel="stylesheet">
    <!--    <link href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">-->
    <link href="css/font-awesome.min.css" rel="stylesheet">
</head>
<script type="text/javascript" src="../js/jquery.min.js" ></script>
<script>
</script>
<body onload="init()">

<div id="wrapper">

    <!-- Sidebar -->
    <ul class="navbar-nav bg-gradient-primary sidebar sidebar-dark accordion" id="accordionSidebar">

        <a class="sidebar-brand d-flex align-items-center justify-content-center" href="main.html">
            <div class="sidebar-brand-icon rotate-n-15">
                <i class="fas fa-laptop-house"></i>
            </div>
            <div class="sidebar-brand-text mx-3">房屋租赁 <sup>8050</sup></div>
        </a>

        <hr class="sidebar-divider">

        <!-- 租赁相关 -->
        <div class="sidebar-heading">
            租赁相关
        </div>

        <!-- 发帖子 -->
        <li class="nav-item">
            <a class="nav-link" href="housePost.html">
                <i class="fas fa-fw fa-edit"></i>
                <span>发布帖子</span></a>
        </li>

        <!-- 我的帖子 -->
        <li class="nav-item active">
            <a class="nav-link" href="houseList.html">
                <i class="fas fa-fw fa-house-user"></i>
                <span>我的帖子</span></a>
        </li>

        <!-- 我的消息 -->
        <li class="nav-item">
            <a class="nav-link" href="unRead.html">
                <i class="fas fa-fw fa-comments"></i>
                <span>我的消息</span></a>
        </li>

        <hr class="sidebar-divider my">

        <!-- 个人相关 -->
        <div class="sidebar-heading">
            个人相关
        </div>

        <!-- 个人资料 -->
        <li class="nav-item">
            <a class="nav-link" href="userInfo.html">
                <i class="fas fa-fw fa-user"></i>
                <span>个人资料</span></a>
        </li>

        <!-- 关于我们 -->
        <li class="nav-item">
            <a class="nav-link" href="about.html">
                <i class="fas fa-fw fa-question"></i>
                <span>关于我们</span></a>
        </li>

        <!-- Divider -->
        <hr class="sidebar-divider d-none d-md-block">

        <!-- Sidebar Toggler (Sidebar) -->
        <div class="text-center d-none d-md-inline">
            <button class="rounded-circle border-0" id="sidebarToggle"></button>
        </div>

    </ul>
    <!-- End of Sidebar -->

    <!-- Content Wrapper -->
    <div id="content-wrapper" class="d-flex flex-column">

        <!-- Main Content -->
        <div id="content">

            <nav class="navbar navbar-expand navbar-light bg-white topbar mb-4 static-top shadow">
                <div style="margin-left: 15px">
                    请按需要修改您的房屋消息
                </div>
                <button id="sidebarToggleTop" class="btn btn-link d-md-none rounded-circle mr-3">
                    <i class="fa fa-bars"></i>
                </button>

                <!-- Topbar Navbar -->
                <ul class="navbar-nav ml-auto">

                    <li class="nav-item dropdown no-arrow">
                        <a class="nav-link dropdown-toggle" href="#" id="userDropdown" role="button"
                           data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                <span class="mr-2 d-none d-lg-inline text-gray-600 small">
                                    欢迎您，
                                    <input type="text" id="newName" style="width: 80px; border-style: none" disabled >
                                </span>
                            <img class="img-profile rounded-circle"
                                 src="img/undraw_profile.svg">
                        </a>
                        <!-- Dropdown - User Information -->
                        <div class="dropdown-menu dropdown-menu-right shadow animated--grow-in"
                             aria-labelledby="userDropdown">

                            <a class="dropdown-item" href="#" data-toggle="modal" data-target="#logoutModal">
                                <i class="fas fa-sign-out-alt fa-sm fa-fw mr-2 text-gray-400"></i>
                                退出登录
                            </a>
                        </div>
                    </li>

                </ul>

            </nav>

            <form id="form1" onsubmit="return false" action="##" style="margin-left: 20px">
                <input type="hidden" id="id">
                <input type="hidden" id="name">
                <input type="hidden" id="status">
                标题:&ensp;&ensp;&ensp;<input type="text" id="title"></br>
                <br>
                地址:&ensp;&ensp;&ensp;<input type="text" id="address"></br>
                <br>
                价格:&ensp;&ensp;&ensp;<input type="text" id="price"></br>
                <br>
                <br>
                <input type="button" value="修改" onclick="update()" style="text-align: center; font-size: 18px; width: 80px" class="btn btn-primary">
                &ensp;&ensp;&ensp;&ensp;
                <a href="houseList.html" style="text-align: center; font-size: 18px; width: 80px" class="btn btn-secondary">取消</a>
            </form>
        </div>

        <!--        底部-->
        <footer class="sticky-footer bg-white">
            <div class="container my-auto">
                <div class="copyright text-center my-auto">
                    <span>致 力 于 打 造 最 方 便 安 全 的 房 屋 租 赁 服 务</span>
                </div>
            </div>
        </footer>

    </div>
</div>

<!--<form id="form1" onsubmit="return false" action="##" >-->
<!--    标题<input type="text" id="title"></br>-->
<!--    地址<input type="text" id="address"></br>-->
<!--    价格<input type="text" id="price"></br>-->
<!--    发布者<input type="text" id="name"></br>-->
<!--    <input type="hidden" id="id"></br>-->
<!--    <input type="button" value="确认" onclick="update()">-->
<!--</form>-->

<!-- Logout Modal-->
<div class="modal fade" id="logoutModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
     aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">确定要退出登录？</h5>
                <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
            </div>
            <div class="modal-body">点击‘退出’后，退出系统...</div>
            <div class="modal-footer">
                <button class="btn btn-secondary" type="button" data-dismiss="modal">取消</button>
                <a class="btn btn-primary" href="login.html">退出</a>
            </div>
        </div>
    </div>
</div>

<!-- Bootstrap core JavaScript-->
<script src="vendor/jquery/jquery.min.js"></script>
<script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

<!-- Core plugin JavaScript-->
<script src="vendor/jquery-easing/jquery.easing.min.js"></script>

<!-- Custom scripts for all pages-->
<script src="js/sb-admin-2.min.js"></script>

<!-- Page level plugins -->
<script src="vendor/chart.js/Chart.min.js"></script>

<!-- Page level custom scripts -->
<script src="js/demo/chart-area-demo.js"></script>

</body>
<script>

    userInfo = JSON.parse(sessionStorage.getItem('userInfo'));
    document.getElementById('newName').value=userInfo.name;
    function house(houseId) {
        sessionStorage.removeItem("houseId");
        sessionStorage.setItem("houseId", houseId);
        if(userInfo.type==1){
            window.location.href = 'houseBuy.html';
        }
        else{
            window.location.href = 'houseSale.html';
        }

    }

    houseId = sessionStorage.getItem("updateHouseId");
    function init() {
        $.ajax({
            type: "GET",
            async: true,
            url: "house/query",
            dataType: "json",        //返回数据形式为json
            data: {"id": houseId},
            success: function (result) {
                console.log(result);//打印服务端返回的数据(调试用)
                if (result.status == 200) {
                    document.getElementById('title').value=result.data.title;
                    document.getElementById('address').value=result.data.address;
                    document.getElementById('price').value=result.data.price;
                    document.getElementById('id').value=result.data.houseId;
                    document.getElementById('name').value=result.data.name;
                    document.getElementById('status').value=result.data.status;
                }
            },
            error: function (errorMsg) {
            }
        });
    }
    function update() {
        var houseInfo={
            id :  $("#id").val(),
            title :  $("#title").val(),
            address :  $("#address").val(),
            price :  $("#price").val(),
            status : $("#status").val()
        }
        $.ajax({
            url: 'house/update',
            method: 'PUT',
            dataType: 'json',
            contentType : 'application/json; charset=UTF-8',
            data: JSON.stringify(houseInfo),
            success: function (result) {
                console.log(result);//打印服务端返回的数据(调试用)
                if (result.status == 200) {
                    alert(result.msg);
                    if(result.msg=="修改成功"){
                        window.location.href = 'houseList.html';
                    }
                }
            },
            error: function () {
                alert("异常！");
            }
        })
    }
</script>


</html>